package com.ruoyi.web.controller.monitor;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.SysFormProcessVo;
import com.ruoyi.system.domain.bo.SysFormProcessBo;
import com.ruoyi.system.service.ISysFormProcessService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 表单和流程配置
 *
 * @author ruoyi
 * @date 2023-06-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/formProcess")
public class SysFormProcessController extends BaseController {

    private final ISysFormProcessService iSysFormProcessService;

    /**
     * 查询表单和流程配置列表
     */
    @SaCheckPermission("system:formProcess:list")
    @GetMapping("/list")
    public TableDataInfo<SysFormProcessVo> list(SysFormProcessBo bo, PageQuery pageQuery) {
        return iSysFormProcessService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出表单和流程配置列表
     */
    @SaCheckPermission("system:formProcess:export")
    @Log(title = "表单和流程配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysFormProcessBo bo, HttpServletResponse response) {
        List<SysFormProcessVo> list = iSysFormProcessService.queryList(bo);
        ExcelUtil.exportExcel(list, "表单和流程配置", SysFormProcessVo.class, response);
    }

    /**
     * 获取表单和流程配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:formProcess:query")
    @GetMapping("/{id}")
    public R<SysFormProcessVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysFormProcessService.queryById(id));
    }

    /**
     * 新增表单和流程配置
     */
    @SaCheckPermission("system:formProcess:add")
    @Log(title = "表单和流程配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysFormProcessBo bo) {
        return toAjax(iSysFormProcessService.insertByBo(bo));
    }

    /**
     * 修改表单和流程配置
     */
    @SaCheckPermission("system:formProcess:edit")
    @Log(title = "表单和流程配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysFormProcessBo bo) {
        return toAjax(iSysFormProcessService.updateByBo(bo));
    }

    /**
     * 删除表单和流程配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:formProcess:remove")
    @Log(title = "表单和流程配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysFormProcessService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
